/* 
 * File:   ball.h
 * Author: iezahel
 *
 * Created on December 28, 2008, 10:22 PM
 */

#ifndef _BALL_H
#define	_BALL_H

#include "pong.h"

class Ball {
    
private:
    double x, y;
    int velocity_x, velocity_y;
    int radius ;

    int default_ball_speed;

    bool new_score; /* Indicates whether the ball is in a position, where a score was made */
    
    SDL_Surface* ball_surface;
    SDL_Surface* screen_surface;

    double distance(double x1, double y1) const { return SQR(x + radius - x1) + SQR(y + radius - y1); }
public:
    Ball(SDL_Surface*, SDL_Surface*, int);
    Ball(const Ball& orig);
    virtual ~Ball();

    void SetX(double val) { x = val; }
    double GetX() const { return x; }

    void SetY(double val) { y = val; }
    double GetY() const { return y; }    
    
    void SetVelocityX(double val) { velocity_x = val; }
    double GetVelocityX() const { return velocity_x; }

    void SetVelocityY(double val) { velocity_y = val; }
    double GetVelocityY() const { return velocity_y; }

    /* Returns the default ball speed */
    int GetSpeedX() const { return default_ball_speed; }
    int GetSpeedY() const { return default_ball_speed; }

    bool IsInScorePos() { 
        bool res = new_score;
        new_score = false;
        return res;
    }

    bool IsStill() const { return velocity_x == 0 && velocity_y == 0; }
    
    int GetRadius() const { return radius; }
    GAME_ERROR_CODES HandleNetworkInput(SDL_Event* event);

    bool CheckCollision(const SDL_Rect* rect) const;
    
    void draw();
    void move(int delta_t);
private:

};

#endif	/* _BALL_H */

